package io.gitee.mingbaobaba.apijson.querycondition.query.template.mapping;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;

/**
 * <p>基于 Fastjson 的默认映射实现</p>
 */
public class FastjsonResultMapper implements ResultMapper {

    @Override
    public <T> T map(JSONObject source, Class<T> targetType) {
        return JSON.parseObject(JSON.toJSONString(source), targetType);
    }

    @Override
    public <T> T map(JSONObject source, TypeReference<T> typeReference) {
        return JSON.parseObject(JSON.toJSONString(source), typeReference);
    }

    @SuppressWarnings("unchecked")
    @Override
    public <T> T map(JSONObject source, JSONObject target) {
        return (T) target;
    }
}

